﻿/*
 * Created by SharpDevelop.
 * User: e397496
 * Date: 17/04/2013
 * Time: 13:55
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using Entity;
using DAO;
using Newtonsoft.Json;
using BussisnesException;

namespace Services{
	
	public class TweetService{
		
		public List<Tweet> getAllTweets(string userNick){
            List<Tweet> tweets = null;
            try
            {
                tweets = new TweetDAO().findByUserWrite(userNick);
            }
            catch (ObjectNotFoundException e ){
                Console.Write(e);
            }
            return tweets;
		}
        
        /// <summary>
        ///  Metodo que busca tods los tweets que tiene que leer un usuario
        /// </summary>
        /// <param name="userNick"></param>
        /// <returns>JSON</returns>
        public String getAllTweetsJson (string userNick){
            List<Tweet> tweets = this.getAllTweets(userNick);
            String result = "";
            if(tweets != null){
                result = JsonConvert.SerializeObject(tweets);
            }
            return result; 
        }

        /// <summary>
        /// Metodo que busca tods los tweets que escribio un usuario
        /// </summary>
        /// <param name="userNick"></param>
        /// <returns>JSON</returns>
 
        public String getAllTweetsFrom(string userNick)
        {
            TweetDAO dao = new TweetDAO();
            List<Tweet> tweets = dao.findByUserRead(userNick);
            return JsonConvert.SerializeObject(tweets);
        }
	}
}
